<template>
  <div>
    <div>
      <p>1,获取所有图书</p>
      <button @click="sbtn">点击获取所有图书</button>
    </div>
    <div>
      <p>2,获取某本图书</p>
      <input type="text" placeholder="请输入书名" v-model="bname" />
      <button @click="mbtn">点击获取书名</button>
    </div>
    <div>
      <p>3,添加一本书</p>
      <input type="text" placeholder="请输入书名" v-model="nameObj.bookname" />
      <input type="text" placeholder="请输入作者" v-model="nameObj.author" />
      <input
        type="text"
        placeholder="请输入出版社"
        v-model="nameObj.publisher"
      />
      <button @click="tbtn">点击添加</button>
    </div>
  </div>
</template>

<script>
import axios from "axios";
axios.defaults.baseURL = "http://123.57.109.30:3006";
export default {
  data() {
    return {
      bname: "",
      nameObj: {
        bookname: "",
        author: "",
        publisher: "",
        appkey: "7250d3eb-18e1-41bc-8bb2-11483665535a",
      },
    };
  },
  methods: {
    //获取所有图书不带参数
    sbtn() {
      //发请求
      axios({
        method: "get",
        url: "/api/getbooks",
      }).then((res) => {
        console.log(res);
      });
    },
    //获取某本图书带参数
    mbtn() {
      axios({
        method: "get",
        url: "/api/getbooks",
        params: {
          bookname: this.bname,
        },
      }).then((res) => {
        console.log(res);
      });
    },
    //添加书籍
    tbtn() {
      axios({
        method: "post",
        url: "/api/addbook",
        data: this.nameObj,
      }).then((res) => {
        console.log(res);
      });
    },
  },
};
</script>

<style>
</style>